/**
*┌──────────────────────────────────────────────────────────────┐
*│　描    述：交易提成接口实现                                                    
*│　作    者：gaotang                                            
*│　版    本：1.0    模板代码自动生成                                                
*│　创建时间：2019-01-29 17:12:18                             
*└──────────────────────────────────────────────────────────────┘
*┌──────────────────────────────────────────────────────────────┐
*│　命名空间： BestTrader.Cms.Repository.SqlServer                                  
*│　类    名： TradeCommissionRepository                                      
*└──────────────────────────────────────────────────────────────┘
*/
using BestTrader.Cms.Core.DbHelper;
using BestTrader.Cms.Core.Options;
using BestTrader.Cms.Core.Repository;
using BestTrader.Cms.IRepository;
using BestTrader.Cms.Models;
using Dapper;
using Microsoft.Extensions.Options;
using System;
using System.Threading.Tasks;

namespace BestTrader.Cms.Repository.SqlServer
{
    public class TradeCommissionRepository:BaseRepository<TradeCommission,Int32>, ITradeCommissionRepository
    {
        public TradeCommissionRepository(IOptionsSnapshot<DbOption> options)
        {
            _dbOption =options.Get("BT.TEST");
            if (_dbOption == null)
            {
                throw new ArgumentNullException(nameof(DbOption));
            }
            _dbConnection = ConnectionFactory.CreateConnection(_dbOption.DbType, _dbOption.ConnectionString);
        }

        public int DeleteLogical(int[] ids)
        {
            DateTime now = DateTime.Now;
            string sql = "update [TradeCommission] set IsDelete=1,ModifyTime=@NowTime  where Id in @Ids";
            return _dbConnection.Execute(sql, new
            {
                NowTime = now,
                Ids = ids

            });
        }

        public async Task<int> DeleteLogicalAsync(int[] ids)
        {
            DateTime now = DateTime.Now;

            string sql = "update [TradeCommission] set IsDelete=1,ModifyTime=@NowTime  where Id in @Ids";
            return await _dbConnection.ExecuteAsync(sql, new
            {
                NowTime=now,
                Ids = ids
            });
        }
    }
}